
function uploadifyPreview_AddItem(pic , name) {
    var html;
    html = '<div class="uploadify-preview-item"><input type="hidden" name="::name::[]" value="::pic::"/><img src="::src::" /><div class="uploadify-preview-item-remove"><a>删除</a></div></div>';
    html = html.replace("::pic::",pic);
    html = html.replace("::src::",pic);
    html = html.replace("::name::",name);
    return html;
}

function myUploadInit(me,multiple) {
    var id = me.context.id;
    var obj = $("#" + id).find("object");
    var preview;
    if (multiple == false) {
        preview = '<div class="uploadify-preview" style="width: 100%;height: 100%;">' +
        '<div class="uploadify-preview-item-list" style="width: 100%;height: 100%;">' +
        '<div class="uploadify-preview-add-full"><span>+</span></div>' +
        '</div>' +
        '</div>';

        $("#" + id).parent().prepend(preview);
        var addArea = $("#" + id).parent().find(".uploadify-preview-add-full");
        obj.removeAttr("width");
        obj.removeAttr("height");
        obj.addClass("uploadify-preview-add-cover");
        addArea.append(obj);
    }else{
        preview = '<div class="uploadify-preview"><div class="uploadify-preview-item-list"><div class="uploadify-preview-add">+</div></div></div>';

        $("#" + id).parent().prepend(preview);
        var addArea = $("#" + id).parent().find(".uploadify-preview-add");
        obj.addClass("uploadify-preview-add-cover");
        addArea.append(obj);
    }

}
function myUploadSuccess(data,file,multiple) {
    var d = JSON.parse(data);
    var wrapBox = $("#" + file.id).parent().parent();
    var id = wrapBox.find(".uploadify").attr("id");
    if (d.s == 1) {
        wrapBox.find("input").val(d.d);
        var item = uploadifyPreview_AddItem(d.d , id );
        if (multiple == false) {
            //单图
            wrapBox.find(".uploadify-preview-item-list")
                .addClass("uploadify-preview-item-full-fill")
                .prepend(item)
            ;
            wrapBox
                .parent().addClass("uploadify-preview-item-full-fill")
            ;
            wrapBox
                .find(".uploadify-preview-item")
                .removeClass("uploadify-preview-item")
                .addClass("uploadify-preview-item-full")
                .addClass("uploadify-preview-item-full-fill")
            ;
            wrapBox
                .find(".uploadify-preview-item-full img")
                .addClass("uploadify-preview-item-full-fill");
        }else{
            //多图
            wrapBox.find(".uploadify-preview-item-list").append(item);
        }
    }else {
        alert(d.i)
    }
}

//图片删除
$(".uploadify-preview-item").live({
    "mouseenter":function () {
        $(this).find(".uploadify-preview-item-remove").fadeIn(100);
    },
    "mouseleave":function () {
        $(this).find(".uploadify-preview-item-remove").fadeOut(100);
    }
});
$(".uploadify-preview-item-full").live({
    "mouseenter":function () {
        $(this).find(".uploadify-preview-item-remove").fadeIn(100);
    },
    "mouseleave":function () {
        $(this).find(".uploadify-preview-item-remove").fadeOut(100);
    }
});
$(".uploadify-preview-item-remove a").live({
    "click":function () {
        $(this).parent().parent().remove();
    }
});